*****************************************
* The White Working Class and the 2016 election
* Nicholas Carnes and Noam Lupu
*****************************************

***************************************************************************
** Generate CPS esimates of percent working class
***************************************************************************

use "cps data.dta", clear

egen median_hh = median(hhincome) , by(year)

gen below_median_hh = (hhincome < median_hh)

gen college = 0 
replace college = 1 if educ>=110

gen ineligible = 0 
replace ineligible = 1 if citizen==5 | age < 18

gen wwc_edincome = (race==100 & hispan==0 & college!=1 & below_median_hh==1) if ineligible!=1
tab year [aw=asecwth], sum(wwc_edincome)

* Figure A2 - over-representation of WWC broken down by individual variables
gen white = 0
replace white = 1 if race==100 & hispan==0 
tab year [aw=asecwth], sum(wwc_edincome)
tab year [aw=asecwth] if ineligible!=1, sum(below_median_hh)
tab year [aw=asecwth] if ineligible!=1, sum(college)
tab year [aw=asecwth] if ineligible!=1, sum(white) 



***************************************************************************
** ANES 1980-2004
***************************************************************************

*** ANES 1980
use "NES1980.dta" , clear
gen voteR = (V800994==1) if V800994>0 & V800994<8
gen college = (V800436>8) if V800436>0 & V800436<98
gen income =  (V800686>16) if V800686>0 & V800686<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V800686
tab V800436
tab V800721
tab V800994
tab V800690
* Median HH income in 1980 was $17,710
* Category includes up to $19,999
gen white = (V800721==1) if V800721<9
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome 
* Figure A2 - over-representation of WWC broken down by individual variables
tab white
tab college
tab income

* develop alternative weights; wwc in sample is 40.39%, wwc in CPS is 33.33%
gen weight_wwc =  0.33328237 / .4039409 if wwc_edincome==1
replace weight_wwc = (1-0.33328237) / (1-.4039409) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc]

* estimate for Figure 2
tab wwc_edincome if voteR==1
tab wwc_edincome if voteR==1 [aw=weight_wwc]
* estimate for Figure 3 *not affected by weighting because we're looking within the white working class
tab voteR if wwc_edincome==1

* estimates for Figure A1 (subjective class identification version of Figure 2)
gen working = 0  
replace working = 1 if  V800690>=1 &  V800690<=3
replace working = 0 if white!=1
tab working if voteR==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab voteR working [aw=weight_wwc], col


*** ANES 1984
use "NES1984.dta" , clear
gen voteR = (V840788==1) if V840788>0 & V840788<8
gen college = (V840438>8) if V840438>0 & V840438<98
gen income =  (V840680>14) if V840680>0 & V840680<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V840680 
tab V840438
tab V840708
tab V840788
tab V840685
* Median HH income in 1984 was $22,415
* Category includes up to $24,999
gen white = (V840708==1) if V840708<9
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome
* Figure A2 - over-representation of WWC broken down by individual variables
tab white
tab college
tab income 

* develop alternative weights
sum wwc_edincome
gen weight_wwc =  0.32447862 / .4424734 if wwc_edincome==1
replace weight_wwc = (1-0.32447862) / (1-.4424734) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc]

* estimate for Figure 2
tab wwc_edincome if voteR==1 [aw=weight_wwc]

* estimate for Figure 3
tab voteR if wwc_edincome==1 

* estimates for Figure A1 (subjective class identification version of Figure 2)
tab V840685, m
gen working = 0  
replace working = 1 if  V840685>=1 &  V840685<=3
replace working = 0 if white!=1
tab working if voteR==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab voteR working [aw=weight_wwc], col

*** ANES 1988
use "NES1988.dta" , clear
gen voteR = (V880763==1) if V880763>0 & V880763<8
gen college = (V880422>5) if V880422>0
gen income =  (V880520>15) if V880520>0 & V880520<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V880520 
tab V880422
tab V880412
tab V880763
tab V880525
* Median HH income in 1988 was $27,225
* Category includes up to $29,999
gen white = (V880412==1) if V880412<9
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome 
* Figure A2 - over-representation of WWC broken down by individual variables
tab income 
tab college
tab white

* develop alternative weights
sum wwc_edincome
gen weight_wwc =  0.31640902 / .4071082 if wwc_edincome==1
replace weight_wwc = (1-0.31640902) / (1-.4071082) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc]

* estimate for Figure 2
tab wwc_edincome if voteR==1
tab wwc_edincome if voteR==1 [aw=weight_wwc]


* estimate for Figure 3
tab voteR if wwc_edincome==1

* estimates for Figure A1 (subjective class identification version of Figure 2)
tab V880525, m
gen working = 0  
replace working = 1 if  V880525>=1 &  V880525<=3
replace working = 0 if white!=1
tab working if voteR==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab voteR working [aw=weight_wwc], col



*** ANES 1992
use "NES1992.dta" , clear
gen voteR = (V925609==1) if V925609>0 & V925609<8
gen college = (V923908>5) if V923908>0
gen income =  (V924104>16) if V924104>0 & V924104<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V924104 
tab V923908
tab V900549
tab V925609
tab V900668

* Median HH income in 1992 was $30,636
* Category includes up to $34,999
gen white = (V900549==1) if V900549<9 & V900549 > 0
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V923009]
* Figure A2 - over-representation of WWC broken down by individual variables
tab income 
tab college
tab white 

* develop alternative weights
sum wwc_edincome [aw=V923009]
gen weight_wwc =  0.30422616 / .4129439 if wwc_edincome==1
replace weight_wwc = (1-0.30422616) / (1-.4129439) if wwc_edincome==0
replace weight_wwc = weight_wwc * V923009
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.30422616 / .2457218 if wwc_edincome==1
replace weight_wwc2 = (1-0.30422616) / (1-.2457218) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if voteR==1 [aw=V923009]
tab wwc_edincome if voteR==1 [aw=weight_wwc]
tab wwc_edincome if voteR==1 [aw=weight_wwc2]


* estimate for Figure 3
tab voteR if wwc_edincome==1 [aw=V923009]

* estimates for Figure A1 (subjective class identification version of Figure 2)
tab V900668, m
gen working = 0  
replace working = 1 if  V900668>=1 &  V900668<=3
replace working = 0 if white!=1
tab working if voteR==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab voteR working [aw=weight_wwc], col


*********************
*** ANES 1996
********************

use "nes96.dta" , clear
gen voteR = (V961082==2) if V961082>0 & V961082<8
gen college = (V960610>5) if V960610>0
gen income =  (V960701>17) if V960701>0 & V960701<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V960701 
tab V960610
tab V960067
tab V961082

* Median HH income in 1996 was $35,492
* Category includes up to $39,999
gen white = (V960067==1) if V960067<9
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V960004]
* Figure A2 - over-representation of WWC broken down by individual variables
tab income 
tab college
tab white

* develop alternative weights
sum wwc_edincome [aw=V960004]
gen weight_wwc =  0.31079164 / .35942  if wwc_edincome==1
replace weight_wwc = (1-0.31079164) / (1-.35942 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V960004
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.31079164 / .3970399 if wwc_edincome==1
replace weight_wwc2 = (1-0.31079164) / (1-.3970399) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if voteR==1 [aw=V960004]
tab wwc_edincome if voteR==1 [aw=weight_wwc]
tab wwc_edincome if voteR==1 [aw=weight_wwc2]

* estimate for Figure 3
tab voteR if wwc_edincome==1 [aw=V960004]

* estimates for Figure A1 (subjective class identification version of Figure 2) -- Q not asked


****************************************
*** ANES 2000
****************************************

use "anes2000TS.dta" , clear
gen voteR = (V001249==3) if V001249>0 & V001249<8
gen college = (V000913>5) if V000913>0
gen income =  (V000994>6) if V000994>0 & V000994<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V000994 
tab V000913
tab V001006a
tab V001249
tab V001005

* Median HH income in 2000 was $41,990
* Category includes up to $49,999
gen white = (V001006a==50) if V001006a<88
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V000002a]
* Figure A2 - over-representation of WWC broken down by individual variables
tab income 
tab college
tab white

* develop alternative weights
sum wwc_edincome [aw=V000002a]
gen weight_wwc =  0.29385664 /  .3494533  if wwc_edincome==1
replace weight_wwc = (1-0.29385664) / (1- .3494533 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V000002a
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.29385664 / .328 if wwc_edincome==1
replace weight_wwc2 = (1-0.29385664) / (1-.328) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if voteR==1 [aw=V000002a]
tab wwc_edincome if voteR==1 [aw=weight_wwc]
tab wwc_edincome if voteR==1 [aw=weight_wwc2]


* estimate for Figure 3
tab voteR if wwc_edincome==1 [aw=V000002a]

* estimates for Figure A1 (subjective class identification version of Figure 2)
tab  V001005, m
gen working = 0  
replace working = 1 if  V001005>=1 &  V001005<=3
replace working = 0 if white!=1
tab working if voteR==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab voteR working [aw=weight_wwc], col

***********************
*** ANES 2004
***********************

use "anes2004TS.dta" , clear
gen voteR = (V045026==3) if V045026>0 & V045026<8
gen college = (V043254>5) if V043254>0
gen income =  (V043293x>15) if V043293x>0 & V043293x<88
* Table A3: look at non-response: income, education, race, voting, subj
tab V043293x 
tab V043254
tab V043299
tab V045026
tab V043298

* Median HH income in 2004 was $44,334
* Category includes up to $44,999
gen white = (V043299==50) if V043299<88
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V040102]


* develop alternative weights
sum wwc_edincome [aw=V040102]
gen weight_wwc =  0.30136674 /   .2707695  if wwc_edincome==1
replace weight_wwc = (1-0.30136674) / (1-  .2707695 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V040102
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.30136674 / .2676056 if wwc_edincome==1
replace weight_wwc2 = (1-0.30136674) / (1-.2676056) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if voteR==1 [aw=V040102]
tab wwc_edincome if voteR==1 [aw=weight_wwc]
tab wwc_edincome if voteR==1 [aw=weight_wwc2]


* estimate for Figure 3
tab voteR if wwc_edincome==1 [aw=V040102]


* estimates for Figure A1 (subjective class identification version of Figure 2)
tab  V043298, m
gen working = 0  
replace working = 1 if  V043298>=1 &  V043298<=3
replace working = 0 if white!=1
tab working if voteR==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab voteR working [aw=weight_wwc], col


***************************************************************************
** ANES 2008
***************************************************************************

use "anes_timeseries_2008_stata12", clear
gen mccain = (V085195==3) if V085195>0
gen college = (V083218x>5) if V083218x>0
gen income = (V083248>17) if V083248>0
* Table A3: look at non-response: income, education, race, voting, subj
tab V083248 
tab V083218x
tab V081102
tab V085195
tab V083250x

* Median HH income in 2008 was $50,303
* Category includes up to $59,999
gen income3 = 1 if V083248<=17 & V083248>0
replace income3 = 2 if V083248>17 & V083248<21
replace income3 = 3 if V083248>=21
gen white = (V081102==1) if V081102>0
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V080102a]


* develop alternative weights
sum wwc_edincome [aw=V080102a]
gen weight_wwc =  0.29024931  /   .3456274  if wwc_edincome==1
replace weight_wwc = (1-0.29024931) / (1-  .3456274 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V080102a
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.29024931 / .3033946 if wwc_edincome==1
replace weight_wwc2 = (1-0.29024931) / (1-.3033946) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]


* estimate for Figure 2
tab wwc_edincome if mccain==1 [aw=V080102a]
tab wwc_edincome if mccain==1 [aw=weight_wwc]
tab wwc_edincome if mccain==1 [aw=weight_wwc2]


* among McCain voters, women were 57% of white working-class voters and 52% of other voters
tab wwc_edincome V081101 if mccain==1 [aw=weight_wwc], row

* estimate for Figure 3
tab mccain if wwc_edincome==1 [aw=weight_wwc]


* estimates for Figure A-3
gen income5 = 1 if V083248>0 & V083248<=9
replace income5 = 2 if V083248>=10 & V083248<=14
replace income5 = 3 if V083248>=15 & V083248<=17
replace income5 = 4 if V083248>=18 & V083248<=20
replace income5 = 5 if V083248>=21

foreach x of numlist 1(1)5 {
	tab mccain if college==1 & income5==`x' & white==1 [aw=weight_wwc]
	tab mccain if college==0 & income5==`x' & white==1 [aw=weight_wwc]
}

* estimates for Figure A1 (subjective class identification version of Figure 2)
tab  V083250x, m
gen working = 0  
replace working = 1 if  V083250x==1
replace working = 0 if white!=1
tab working if mccain==1 [aw=weight_wwc], m
tab working [aw=weight_wwc], m
tab mccain working [aw=weight_wwc], col


***************************************************************************
** ANES 2012
***************************************************************************

use "anes_timeseries_2012", clear
gen romney = (presvote2012_x==2) if presvote2012_x>0
gen obama = (presvote2012_x==1) if presvote2012_x>0
gen college = (dem_edu>12 & dem_edu<95) if dem_edu>0
gen income = (inc_incgroup_pre>15) if inc_incgroup_pre>0
* Table A3: look at non-response: income, education, race, voting, subj
tab inc_incgroup_pre 
tab dem_edu
tab dem_raceeth_x
tab presvote2012_x
tab dem_whichclass

* Median HH income in 2012 was $51,017
* Category includes up to $54,999
gen income3 = 1 if inc_incgroup_pre<16 & inc_incgroup_pre>0
replace income3 = 2 if inc_incgroup_pre>=16 & inc_incgroup_pre<=22
replace income3 = 3 if inc_incgroup_pre>22
gen white = (dem_raceeth_x==1) if dem_raceeth_x>0
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=weight_full]


* develop alternative weights
sum wwc_edincome [aw=weight_full]
gen weight_wwc =  0.27770657  /   .2837203  if wwc_edincome==1
replace weight_wwc = (1-0.27770657) / (1-  .2837203 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * weight_full
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.27770657 /  .2390335 if wwc_edincome==1
replace weight_wwc2 = (1-0.27770657) / (1- .2390335) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if romney==1 [aw=weight_full]
tab wwc_edincome if romney==1 [aw=weight_wwc]
tab wwc_edincome if romney==1 [aw=weight_wwc2]


* among Romney voters, women were 51% of white working-class voters and 49% of other voters
tab wwc_edincome gender_respondent_x if romney==1 [aw=weight_wwc], row

* estimate for Figure 3
tab romney if wwc_edincome==1 [aw=weight_wwc]


* estimates for Figure A-3
gen income5 = 1 if inc_incgroup_pre>0 & inc_incgroup_pre<=6
replace income5 = 2 if inc_incgroup_pre>=7 & inc_incgroup_pre<=12
replace income5 = 3 if inc_incgroup_pre>=13 & inc_incgroup_pre<=17
replace income5 = 4 if inc_incgroup_pre>=18 & inc_incgroup_pre<=22
replace income5 = 5 if inc_incgroup_pre>=23


foreach x of numlist 1(1)5 {
	tab romney if college==1 & income5==`x' & white==1 [aw=weight_wwc]
	tab romney if college==0 & income5==`x' & white==1 [aw=weight_wwc]
}



* Code past votes (2008)
recode interest_whovote2008 (1 = 1) (2 5 -8 -9 = 0) (-1 = .), gen(pastD)
replace pastD = 0 if interest_voted2008==2
recode interest_whovote2008 (2 = 1) (1 5 -8 -9 = 0) (-1 = .), gen(pastR)
replace pastR = 0 if interest_voted2008==2
gen pastnon = (interest_voted2008==2) if interest_voted2008>0

* Code switchers
gen DRswitch = (pastD==1 & romney==1) if pastD!=. & romney!=.
gen RDswitch = (pastR==1 & obama==1) if pastR!=. & obama!=.
gen nonRswitch = (pastnon==1 & romney==1) if pastnon!=. & romney!=.
gen nonDswitch = (pastnon==1 & obama==1) if pastnon!=. & obama!=.

* Estimates for Table 1
tab DRswitch if romney==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc]
tab RDswitch if obama==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc]
tab nonRswitch if romney==1 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc]
tab nonDswitch if obama==1 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc]

* Estimates for Table-A7
tab DRswitch if romney==1 [aw=weight_full]
tab wwc_edincome if DRswitch==1 [aw=weight_full]
tab RDswitch if obama==1 [aw=weight_full]
tab wwc_edincome if RDswitch==1 [aw=weight_full]
tab nonRswitch if romney==1 [aw=weight_full]
tab wwc_edincome if nonRswitch==1 [aw=weight_full]
tab nonDswitch if obama==1 [aw=weight_full]
tab wwc_edincome if nonDswitch==1 [aw=weight_full]

* Estimates for Table A6
tab DRswitch if romney==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc2]
tab RDswitch if obama==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc2]
tab nonRswitch if romney==1 [aw=weight_wwc2]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc2]
tab nonDswitch if obama==1 [aw=weight_wwc2]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc2]

* Estimates for Table A4
gen age = dem_age_r_x if dem_age_r_x>0
gen female = (gender_respondent_x==2)
gen Rswitch = (DRswitch==1 | nonRswitch==1)
xi: reg Rswitch wwc_edincome age female [pw=weight_wwc], robust
gen allswitch = (DRswitch==1 | nonRswitch==1 | RDswitch==1 | nonDswitch==1)
xi: reg allswitch wwc_edincome age female [pw=weight_wwc], robust

* estimates for Figure A1 (subjective class identification version of Figure 2)
gen class = ""
replace class = "working" if  dem_whichclass==2
replace class = "middle" if dem_whichclass==1
replace class = "other" if dem_whichclass==0 | dem_whichclass==3 | dem_whichclass==4 | dem_whichclass==5

replace class = "working" if  dem_chclass==2
replace class = "middle" if dem_chclass==1
replace class = "other" if dem_chclass==0 | dem_chclass==3 | dem_chclass==4 | dem_chclass==5

replace class = "" if white!=1
tab  class if romney==1 [aw=weight_wwc]
tab  class [aw=weight_wwc], m
tab romney class [aw=weight_wwc], col


***************************************************************************
** ANES 2016
***************************************************************************

use "anes_timeseries_2016", clear
gen trump = (V162034a==2) if V162034a>0
gen clinton = (V162034a==1) if V162034a>0
gen college = (V161270>12 & V161270<90)
gen income = (V161361x>16) if V161361x>0
* Table A3: look at non-response: income, education, race, voting, subj
tab V161361x
tab V161270
tab V161310x
tab V162034a
tab V161305a  
tab V161305b 
tab V161307 
tab V162129 
tab V162130 
tab V162132

* Median HH income in 2016 was $59,039
* Category includes up to $59,999
gen income3 = 1 if V161361x<=16 & V161361x>0
replace income3 = 2 if V161361x>16 & V161361x<=22
replace income3 = 3 if V161361x>22
gen white = (V161310x==1) if V161310x>0
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V160102]


* develop alternative weights
sum wwc_edincome [aw=V160102]
gen weight_wwc =  0.25305546  /   .2544896  if wwc_edincome==1
replace weight_wwc = (1-0.25305546) / (1-  .2544896 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V160102
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.25305546 /  .2489504 if wwc_edincome==1
replace weight_wwc2 = (1-0.25305546) / (1- .2489504) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if trump==1 [aw=V160102]
tab wwc_edincome if trump==1 [aw=weight_wwc]
tab wwc_edincome if trump==1 [aw=weight_wwc2]

* among Trump voters, women were 62% of white working-class voters and 45% of other voters
tab wwc_edincome V161342 if trump==1 & V161342>0 [aw=weight_wwc], row

* Estimate for Figure 3
tab trump if wwc_edincome==1 [aw=weight_wwc]


* Code past votes (2012)
recode V161006 (1 = 1) (2 5 6 -8 -9 = 0) (-1 = .), gen(pastD)
replace pastD = 0 if V161005==2
recode V161006 (2 = 1) (1 5 6 -8 -9 = 0) (-1 = .), gen(pastR)
replace pastR = 0 if V161005==2
gen pastnon = (V161005==2 | V161006==6) if V161005>0

* Code switchers
gen DRswitch = (pastD==1 & trump==1) if pastD!=. & trump!=.
gen RDswitch = (pastR==1 & clinton==1) if pastR!=. & clinton!=.
gen nonRswitch = (pastnon==1 & trump==1) if pastnon!=. & trump!=.
gen nonDswitch = (pastnon==1 & clinton==1) if pastnon!=. & clinton!=.

* Estimates for Table 1
tab DRswitch if trump==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc]
tab RDswitch if clinton==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc]
tab nonRswitch if trump==1 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc]
tab nonDswitch if clinton==1 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc]

* Estimates for Table-A7
tab DRswitch if trump==1 [aw=V160102]
tab wwc_edincome if DRswitch==1 [aw=V160102]
tab RDswitch if clinton==1 [aw=V160102]
tab wwc_edincome if RDswitch==1 [aw=V160102]
tab nonRswitch if trump==1 [aw=V160102]
tab wwc_edincome if nonRswitch==1 [aw=V160102]
tab nonDswitch if clinton==1 [aw=V160102]
tab wwc_edincome if nonDswitch==1 [aw=V160102]

* Estimates for Table A6
tab DRswitch if trump==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc2]
tab RDswitch if clinton==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc2]
tab nonRswitch if trump==1 [aw=weight_wwc2]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc2]
tab nonDswitch if clinton==1 [aw=weight_wwc2]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc2]


* Estimates for Table A4
gen age = V161267 if V161267>0
gen female = 1 if V161002==2
replace female = 0 if V161002==1
replace female = 1 if V165723==2
replace female = 0 if V165723==1
gen trumpswitch = (DRswitch==1 | nonRswitch==1)
xi: reg trumpswitch wwc_edincome age female [pw=weight_wwc], robust
gen allswitch = (DRswitch==1 | nonRswitch==1 | RDswitch==1 | nonDswitch==1)
xi: reg allswitch wwc_edincome age female [pw=weight_wwc], robust


* estimates for Figure A-3
gen income5 = 1 if V161361x>0 & V161361x<=8
replace income5 = 2 if V161361x>=9 & V161361x<=13
replace income5 = 3 if V161361x>=14 & V161361x<=19
replace income5 = 4 if V161361x>=20 & V161361x<=24
replace income5 = 5 if V161361x>=25

foreach x of numlist 1(1)5 {
	tab trump if college==1 & income5==`x' & white==1 [aw=weight_wwc]
	tab trump if college==0 & income5==`x' & white==1 [aw=weight_wwc]
}


* Using occupation instead of HH income (Table A1)
do "occupation coding for ANES 2016.do"
replace wwc_occupation = 0 if white==0
replace wwc_occupation = . if white==.
* generate occupation non-response rate 
tab V161291b
* the occupational and ed/income measures agree over 80% of the time
tab wwc_occupation wwc_edincome [aw=weight_wwc], cell
	tab wwc_edincome if trump==1 [aw=weight_wwc]
	tab wwc_occupation if trump==1 [aw=weight_wwc]
	tab trump if wwc_edincome==1 [aw=weight_wwc]
	tab trump if wwc_occupation==1 [aw=weight_wwc]
	tab wwc_edincome if nonRswitch==1 | DRswitch==1 [aw=weight_wwc]
	tab wwc_occupation if nonRswitch==1 | DRswitch==1 [aw=weight_wwc]
	tab wwc_edincome if nonDswitch==1 | RDswitch==1 [aw=weight_wwc]
	tab wwc_occupation if nonDswitch==1 | RDswitch==1 [aw=weight_wwc]
*who are the non-overlapping 20%
tab wwc_occupation wwc_edincome [aw=weight_wwc], cell
tab trump if wwc_edincome==1 [aw=weight_wwc]
tab trump if wwc_occupation==1 & wwc_edincome==0 [aw=weight_wwc]

* Validated vote reanalysis (Table A2)
drop V160001
rename V160001_orig V160001
merge 1:1 V160001 using "ANES 2016\anes_timeseries_2016_voteval.dta"
	tab wwc_edincome if trump==1 [aw=weight_wwc]
	tab wwc_edincome if trump==1 & clerical_review==1 [aw=weight_wwc]
	tab trump if wwc_edincome==1 [aw=weight_wwc]
	tab trump if wwc_edincome==1 & clerical_review==1 [aw=weight_wwc]
	tab wwc_edincome if nonRswitch==1 | DRswitch==1 [aw=weight_wwc]
	tab wwc_edincome if (nonRswitch==1 | DRswitch==1) & vote2016_clerical==1 & vote2012_clerical==1 [aw=weight_wwc]
	tab wwc_edincome if nonDswitch==1 | RDswitch==1 [aw=weight_wwc]
	tab wwc_edincome if (nonDswitch==1 | RDswitch==1) & vote2016_clerical==1 & vote2012_clerical==1 [aw=weight_wwc]

* estimates for Figure A1 (subjective class identification version of Figure 2)
gen class = ""
replace class = "working" if  V161305a==2
replace class = "middle" if V161305a==1
replace class = "other" if V161305a==0 | V161305a==3 | V161305a==4 | V161305a==5
replace class = "working" if  V161305b==2
replace class = "middle" if V161305b==1
replace class = "other" if V161305b==0 | V161305b==3 | V161305b==4 | V161305b==5

replace class = "working" if  V161307==2
replace class = "middle" if V161307==3
replace class = "other" if V161307==1 | V161307==4

replace class = "working" if  V162129==2
replace class = "middle" if V162129==1
replace class = "other" if V162129==0 | V162129==3 | V162129==4 

replace class = "working" if  V162130==2
replace class = "middle" if V162130==1
replace class = "other" if V162130==0 | V162130==3 | V162130==4 | V162130==5 

replace class = "working" if V162132==2
replace class = "middle" if V162132==3
replace class = "other" if V162132==1 | V162132==4 

replace class = "" if white!=1
tab  class if trump==1 [aw=weight_wwc]
tab  class [aw=weight_wwc], m
tab trump class [aw=weight_wwc], col

	
	
***************************************************************************
** CCES 2008
***************************************************************************

use "cces_2008_common.dta", clear
gen mccain = (CC410==1) if CC410<8
gen college = (V213>4) if V213!=.
gen income = (V246>8) if V246<15
* Table A3: look at non-response: income, education, race, voting
tab V246
tab V213
tab V211
tab CC410	

* Median HH income in 2008 was $50,303
* Category includes up to $59,999
gen white = (V211==1)
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V201]


* develop alternative weights
sum wwc_edincome [aw=V201]
gen weight_wwc =  0.29024931  /   .3540216  if wwc_edincome==1
replace weight_wwc = (1-0.29024931) / (1-  .3540216 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V201
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.29024931 /  .3490753  if wwc_edincome==1
replace weight_wwc2 = (1-0.29024931) / (1- .3490753 ) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if mccain==1 [aw=V201]
tab wwc_edincome if mccain==1 [aw=weight_wwc]
tab wwc_edincome if mccain==1 [aw=weight_wwc2]


* among McCain voters, women were 57% of white working-class voters and 41% of other voters
tab wwc_edincome V208 if mccain==1 [aw=weight_wwc], row

* Estimate for Figure 3
tab mccain if wwc_edincome==1 [aw=weight_wwc]



***************************************************************************
** CCES 2012
***************************************************************************

use "CCES12_Common_VV.dta", clear
gen romney = (CC410a==2) if CC410a<4
gen obama = (CC410a==1) if CC410a<4
gen college = (educ>4) if educ!=.
gen income = (faminc>6) if faminc<97
* Table A3: look at non-response: income, education, race, voting
tab faminc, m
tab educ, m
tab race, m
tab CC410a, m


* Median HH income in 2012 was $51,017
* Category includes up to $59,999
gen white = (race==1)
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=V103]


* develop alternative weights
sum wwc_edincome [aw=V103]
gen weight_wwc =  0.27770657  /   .3651933  if wwc_edincome==1
replace weight_wwc = (1-0.27770657) / (1-  .3651933 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * V103
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.27770657 /  .3184398  if wwc_edincome==1
replace weight_wwc2 = (1-0.27770657) / (1- .3184398 ) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

* estimate for Figure 2
tab wwc_edincome if romney==1 [aw=V103]
tab wwc_edincome if romney==1 [aw=weight_wwc]
tab wwc_edincome if romney==1 [aw=weight_wwc2]


* among Romney voters, women were 54% of white working-class voters and 45% of other voters
tab wwc_edincome gender if romney==1 [aw=weight_wwc], row

* Estimate for Figure 3
tab romney if wwc_edincome==1 [aw=weight_wwc]


* Code past votes (2008)
gen pastD = (CC317==1)
replace pastD=0 if CC316<3
gen pastR = (CC317==2)
replace pastR=0 if CC316<3
gen pastnon = (CC316<3)

* Code switchers
gen DRswitch = (pastD==1 & romney==1) if pastD!=. & romney!=.
gen RDswitch = (pastR==1 & obama==1) if pastR!=. & obama!=.
gen nonRswitch = (pastnon==1 & romney==1) if pastnon!=. & romney!=.
gen nonDswitch = (pastnon==1 & obama==1) if pastnon!=. & obama!=.

* Estimates for Table 1
tab DRswitch if romney==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc]
tab RDswitch if obama==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc]
tab nonRswitch if romney==1 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc]
tab nonDswitch if obama==1 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc]

* Estimates for Table-A7
tab DRswitch if romney==1 [aw=V103]
tab wwc_edincome if DRswitch==1 [aw=V103]
tab RDswitch if obama==1 [aw=V103]
tab wwc_edincome if RDswitch==1 [aw=V103]
tab nonRswitch if romney==1 [aw=V103]
tab wwc_edincome if nonRswitch==1 [aw=V103]
tab nonDswitch if obama==1 [aw=V103]
tab wwc_edincome if nonDswitch==1 [aw=V103]

* Estimates for Table A6
tab DRswitch if romney==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc2]
tab RDswitch if obama==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc2]
tab nonRswitch if romney==1 [aw=weight_wwc2]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc2]
tab nonDswitch if obama==1 [aw=weight_wwc2]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc2]

* Estimates for Table A4
gen age = 2012-birthyr
gen female = (gender==2)
gen Rswitch = (DRswitch==1 | nonRswitch==1)
xi: reg Rswitch wwc_edincome age female [pw=weight_wwc], robust
preserve
keep Rswitch wwc_edincome age female weight_wwc
save "CCES2012switch.dta", replace
restore




***************************************************************************
** CCES 2016
***************************************************************************

use "CCES16_Common_OUTPUT_Feb2018_VV.dta", clear
gen trump = (CC16_410a==1) if CC16_410a<6 | CC16_410a==8
gen clinton = (CC16_410a==2) if CC16_410a<6 | CC16_410a==8
gen college = (educ>4) if educ!=.
gen income = (faminc>6) if faminc<97
* Table A3: look at non-response: income, education, race, voting
tab faminc, m
tab educ, m
tab race, m
tab CC16_410a, m
* Median HH income in 2016 was $59,039
* Category includes up to $59,999
gen white = (race==1)
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.
* Figure 1 - pct of respondents
tab wwc_edincome [aw=commonweight_post]


* develop alternative weights
sum wwc_edincome [aw=commonweight_post]
gen weight_wwc =  0.25305546  /   .3544467  if wwc_edincome==1
replace weight_wwc = (1- 0.25305546) / (1-  .3544467 ) if wwc_edincome==0
replace weight_wwc = weight_wwc * commonweight_post
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome
gen weight_wwc2 =  0.25305546 /  .2996264   if wwc_edincome==1
replace weight_wwc2 = (1-0.25305546) / (1- .2996264  ) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]

sum wwc_edincome [aw=commonweight_vv_post]
gen weight_vv_wwc =  0.25305546  /   .3423384  if wwc_edincome==1
replace weight_vv_wwc = (1- 0.25305546) / (1-  .3423384 ) if wwc_edincome==0
replace weight_vv_wwc = weight_vv_wwc * commonweight_vv_post


* estimate for Figure 2
tab wwc_edincome if trump==1 [aw=commonweight_post]
tab wwc_edincome if trump==1 [aw=weight_wwc]
tab wwc_edincome if trump==1 [aw=weight_wwc2]

* among Trump voters, women were 51% of white working-class voters and 42% of other voters
tab wwc_edincome gender if trump==1 [aw=weight_wwc], row

* Estimate for Figure 3
tab trump if wwc_edincome==1 [aw=weight_wwc]


* Code past votes (2012)
gen pastD = (CC16_326==1)
replace pastD=0 if CC16_316<3
gen pastR = (CC16_326==2)
replace pastR=0 if CC16_316<3
gen pastnon = (CC16_326==4 | CC16_316<3)

* Code switchers
gen DRswitch = (pastD==1 & trump==1) if pastD!=. & trump!=.
gen RDswitch = (pastR==1 & clinton==1) if pastR!=. & clinton!=.
gen nonRswitch = (pastnon==1 & trump==1) if pastnon!=. & trump!=.
gen nonDswitch = (pastnon==1 & clinton==1) if pastnon!=. & clinton!=.

* Estimates for Table 1
tab DRswitch if trump==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc]
tab RDswitch if clinton==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc]
tab nonRswitch if trump==1 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc]
tab nonDswitch if clinton==1 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc]

* Estimates for Table-A7
tab DRswitch if trump==1 [aw=commonweight_post]
tab wwc_edincome if DRswitch==1 [aw=commonweight_post]
tab RDswitch if clinton==1 [aw=commonweight_post]
tab wwc_edincome if RDswitch==1 [aw=commonweight_post]
tab nonRswitch if trump==1 [aw=commonweight_post]
tab wwc_edincome if nonRswitch==1 [aw=commonweight_post]
tab nonDswitch if clinton==1 [aw=commonweight_post]
tab wwc_edincome if nonDswitch==1 [aw=commonweight_post]

* Estimates for Table A6
tab DRswitch if trump==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc2]
tab RDswitch if clinton==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc2]
tab nonRswitch if trump==1 [aw=weight_wwc2]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc2]
tab nonDswitch if clinton==1 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc2]



* Estimates for Table A4
gen age = 2016-birthyr
gen female = (gender==2)
gen Rswitch = (DRswitch==1 | nonRswitch==1)
xi: reg Rswitch wwc_edincome age female [pw=weight_wwc], robust


* Table A2: Validated vote renalaysis
tab wwc_edincome if trump==1 [aw=weight_wwc]
tab wwc_edincome if trump==1 & CL_matched=="Y" [aw=weight_vv_wwc]
tab trump if wwc_edincome==1 [aw=weight_wwc]
tab trump if wwc_edincome==1 & CL_matched=="Y" [aw=weight_vv_wwc]
tab wwc_edincome if (nonRswitch==1 | DRswitch==1) [aw=weight_wwc]
tab wwc_edincome if (nonRswitch==1 | DRswitch==1) & CL_matched=="Y" [aw=weight_vv_wwc]
tab wwc_edincome if (nonDswitch==1 | RDswitch==1) [aw=weight_wwc]
tab wwc_edincome if (nonDswitch==1 | RDswitch==1) & CL_matched=="Y" [aw=weight_vv_wwc]


*** Swing states
* CCES State codes: FL=12, IA=19, MI=26, OH=39, PA=42, WI=55

* Estimates for Figure 4
tab wwc_edincome if trump==1 [aw=weight_wwc]
tab wwc_edincome if trump==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if trump==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if trump==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if trump==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if trump==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if trump==1 & inputstate==55 [aw=weight_wwc]

tab trump if wwc_edincome==1 [aw=weight_wwc]
tab trump if wwc_edincome==1 & inputstate==12 [aw=weight_wwc]
tab trump if wwc_edincome==1 & inputstate==19 [aw=weight_wwc]
tab trump if wwc_edincome==1 & inputstate==26 [aw=weight_wwc]
tab trump if wwc_edincome==1 & inputstate==39 [aw=weight_wwc]
tab trump if wwc_edincome==1 & inputstate==42 [aw=weight_wwc]
tab trump if wwc_edincome==1 & inputstate==55 [aw=weight_wwc]

gen voter = (CC16_410a<6 | CC16_410a==8)
tab wwc_edincome if voter==1 [aw=weight_wwc]
tab wwc_edincome if voter==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if voter==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if voter==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if voter==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if voter==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if voter==1 & inputstate==55 [aw=weight_wwc]

tab wwc_edincome if clinton==1 [aw=weight_wwc]
tab wwc_edincome if clinton==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if clinton==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if clinton==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if clinton==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if clinton==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if clinton==1 & inputstate==55 [aw=weight_wwc]


* Estimates for Table 3
* FL=12
tab DRswitch if trump==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 & inputstate==12 [aw=weight_wwc]
tab RDswitch if clinton==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 & inputstate==12 [aw=weight_wwc]
tab nonRswitch if trump==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 & inputstate==12 [aw=weight_wwc]
tab nonDswitch if clinton==1 & inputstate==12 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 & inputstate==12 [aw=weight_wwc]
* IA=19
tab DRswitch if trump==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 & inputstate==19 [aw=weight_wwc]
tab RDswitch if clinton==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 & inputstate==19 [aw=weight_wwc]
tab nonRswitch if trump==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 & inputstate==19 [aw=weight_wwc]
tab nonDswitch if clinton==1 & inputstate==19 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 & inputstate==19 [aw=weight_wwc]
* MI=26
tab DRswitch if trump==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 & inputstate==26 [aw=weight_wwc]
tab RDswitch if clinton==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 & inputstate==26 [aw=weight_wwc]
tab nonRswitch if trump==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 & inputstate==26 [aw=weight_wwc]
tab nonDswitch if clinton==1 & inputstate==26 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 & inputstate==26 [aw=weight_wwc]
* OH=39
tab DRswitch if trump==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 & inputstate==39 [aw=weight_wwc]
tab RDswitch if clinton==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 & inputstate==39 [aw=weight_wwc]
tab nonRswitch if trump==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 & inputstate==39 [aw=weight_wwc]
tab nonDswitch if clinton==1 & inputstate==39 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 & inputstate==39 [aw=weight_wwc]
* PA=42
tab DRswitch if trump==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 & inputstate==42 [aw=weight_wwc]
tab RDswitch if clinton==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 & inputstate==42 [aw=weight_wwc]
tab nonRswitch if trump==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 & inputstate==42 [aw=weight_wwc]
tab nonDswitch if clinton==1 & inputstate==42 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 & inputstate==42 [aw=weight_wwc]
* WI=55
tab DRswitch if trump==1 & inputstate==55 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 & inputstate==55 [aw=weight_wwc]
tab RDswitch if clinton==1 & inputstate==55 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 & inputstate==55 [aw=weight_wwc]
tab nonRswitch if trump==1 & inputstate==55 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 & inputstate==55 [aw=weight_wwc]
tab nonDswitch if clinton==1 & inputstate==55 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 & inputstate==55 [aw=weight_wwc]

* Estimates for Table 2
gen swingstate = (inputstate==12 | inputstate==19 | inputstate==26 | inputstate==39 | inputstate==42 | inputstate==55)
gen bluewall = (inputstate==26 | inputstate==42 | inputstate==55)
gen trumpswitch = (DRswitch==1 | nonRswitch==1)
xi: reg trump wwc_edincome##swingstate age female [pw=weight_wwc], robust
xi: reg trump wwc_edincome##bluewall age female [pw=weight_wwc], robust
xi: reg trumpswitch wwc_edincome##swingstate age female [pw=weight_wwc], robust
xi: reg trumpswitch wwc_edincome##bluewall age female [pw=weight_wwc], robust

* Estimates for Table A8
xi: reg trump wwc_edincome##swingstate age female [pw=commonweight_post], robust
xi: reg trump wwc_edincome##bluewall age female [pw=commonweight_post], robust
xi: reg trumpswitch wwc_edincome##swingstate age female [pw=commonweight_post], robust
xi: reg trumpswitch wwc_edincome##bluewall age female [pw=commonweight_post], robust

* Estimates for Table A9
xi: reg trump wwc_edincome##swingstate age female [pw=weight_wwc2], robust
xi: reg trump wwc_edincome##bluewall age female [pw=weight_wwc2], robust
xi: reg trumpswitch wwc_edincome##swingstate age female [pw=weight_wwc2], robust
xi: reg trumpswitch wwc_edincome##bluewall age female [pw=weight_wwc2], robust



***************************************************************************
** VOTER 2012-2016
***************************************************************************

use "VOTER_Survey_July17_Release1-dta", clear
gen trump = (presvote16post_2016==2) if presvote16post_2016<6
gen clinton = (presvote16post_2016==1) if presvote16post_2016<6
gen college = (educ_2016>4) if educ_2016!=.
gen income = (faminc_2016>6) if faminc_2016<97
gen white = (race_2016==1)
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.

* Table A3: look at non-response: income, education, race, voting
tab faminc_2016, m
tab educ_2016, m
tab race_2016, m
tab presvote16post_2016, m

* Figure 1 - pct of sample
tab wwc_edincome [aw=weight_2016]

* develop alternative weights
sum wwc_edincome [aw=weight_2016]
gen weight_wwc =  0.25305546  /   .3433138   if wwc_edincome==1
replace weight_wwc = (1- 0.25305546) / (1-  .3433138  ) if wwc_edincome==0
replace weight_wwc = weight_wwc * weight_2016
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome if weight_2016!=.
gen weight_wwc2 =  0.25305546 /  .4581961   if wwc_edincome==1
replace weight_wwc2 = (1-0.25305546) / (1- .4581961  ) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]


* Code past votes (2012)
gen pastD = (post_presvote12_2012==1) if post_presvote12_2012!=6
gen pastR = (post_presvote12_2012==2) if post_presvote12_2012!=6

* Code switchers
gen DRswitch = (pastD==1 & trump==1) if pastD!=. & trump!=.
gen RDswitch = (pastR==1 & clinton==1) if pastR!=. & clinton!=.

* Estimates for Table 1
tab DRswitch if trump==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc]
tab RDswitch if clinton==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc]

* Estimates for Table-A7
tab DRswitch if trump==1 [aw=weight_2016]
tab wwc_edincome if DRswitch==1 [aw=weight_2016]
tab RDswitch if clinton==1 [aw=weight_2016]
tab wwc_edincome if RDswitch==1 [aw=weight_2016]

* Estimates for Table A6
tab DRswitch if trump==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc2]
tab RDswitch if clinton==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc2]


* Estimates for Table A4
gen age = 2016-birthyr_baseline
gen female = (gender_baseline==2)
gen Rswitch = (DRswitch==1)
xi: reg Rswitch wwc_edincome age female [pw=weight_wwc], robust


* Code past votes (2008)
rename pastD pastD12
rename pastR pastR12
gen pastD08 = (presvote08_baseline==1) if presvote08_baseline!=5
gen pastR08 = (presvote08_baseline==2) if presvote08_baseline!=5

* Code switchers
gen DRswitch08 = (pastD08==1 & pastR12==1) if pastD08!=. & pastR12!=.
gen RDswitch08 = (pastR08==1 & pastD12==1) if pastR08!=. & pastD12!=.

* Estimates for Table 1
tab DRswitch08 if pastR12==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch08==1 [aw=weight_wwc]
tab RDswitch08 if pastD12==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch08==1 [aw=weight_wwc]

* Estimates for Table-A7
tab DRswitch08 if pastR12==1 [aw=weight_2016]
tab wwc_edincome if DRswitch08==1 [aw=weight_2016]
tab RDswitch08 if pastD12==1 [aw=weight_2016]
tab wwc_edincome if RDswitch08==1 [aw=weight_2016]

* Estimates for Table A6
tab DRswitch08 if pastR12==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch08==1 [aw=weight_wwc2]
tab RDswitch08 if pastD12==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch08==1 [aw=weight_wwc2]


* Estimates for Table A4
gen age12 = 2012-birthyr_baseline
gen Rswitch08 = (DRswitch08==1)
xi: reg Rswitch08 wwc_edincome age12 female [pw=weight_wwc], robust


* Estimates for Table-A5
tab post_pid3_2012 if DRswitch==1 [aw=weight_wwc]
tab post_pid3_2012 if RDswitch==1 [aw=weight_wwc]



***************************************************************************
** ANES 2000-2004
***************************************************************************

* ANES 2000-2004
use "anes_mergedfile_2000to2004", clear
gen bush = (M045049a==3) if M045049a<8
gen kerry = (M045049a==1) if M045049a<8
gen college = (M000913>4)
gen income = (M000994>6)
gen white = (M001006a==50)
gen wwc_edincome = (white==1 & college==0 & income==0) if white!=. & college!=. & income!=.

* Figure 1 - pct of sample
tab wwc_edincome [aw=WT04]

* develop alternative weights
sum wwc_edincome [aw=WT04]
gen weight_wwc =  0.25305546  /   .242231   if wwc_edincome==1
replace weight_wwc = (1- 0.25305546) / (1-  .242231  ) if wwc_edincome==0
replace weight_wwc = weight_wwc * WT04
tab wwc_edincome [aw=weight_wwc]

sum wwc_edincome if WT04!=.
gen weight_wwc2 =  0.25305546 /  .222619   if wwc_edincome==1
replace weight_wwc2 = (1-0.25305546) / (1- .222619  ) if wwc_edincome==0
tab wwc_edincome [aw=weight_wwc2]


* Code past votes (2000)
gen pastD = (M001249==1)
replace pastD=0 if M001241<4
gen pastR = (M001249==3)
replace pastR=0 if M001241<4
gen pastnon = (M001241<4)

* Code switchers
gen DRswitch = (pastD==1 & bush==1) if pastD!=. & bush!=.
gen RDswitch = (pastR==1 & kerry==1) if pastR!=. & kerry!=.
gen nonRswitch = (pastnon==1 & bush==1) if pastnon!=. & bush!=.
gen nonDswitch = (pastnon==1 & kerry==1) if pastnon!=. & kerry!=.

* Estimates for Table 1
tab DRswitch if bush==1 [aw=weight_wwc]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc]
tab RDswitch if kerry==1 [aw=weight_wwc]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc]
tab nonRswitch if bush==1 [aw=weight_wwc]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc]
tab nonDswitch if kerry==1 [aw=weight_wwc]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc]

* Estimates for Table-A6
tab DRswitch if bush==1 [aw=WT04]
tab wwc_edincome if DRswitch==1 [aw=WT04]
tab RDswitch if kerry==1 [aw=WT04]
tab wwc_edincome if RDswitch==1 [aw=WT04]
tab nonRswitch if bush==1 [aw=WT04]
tab wwc_edincome if nonRswitch==1 [aw=WT04]
tab nonDswitch if kerry==1 [aw=WT04]
tab wwc_edincome if nonDswitch==1 [aw=WT04]


* Estimates for Table A6
tab DRswitch if bush==1 [aw=weight_wwc2]
tab wwc_edincome if DRswitch==1 [aw=weight_wwc2]
tab RDswitch if kerry==1 [aw=weight_wwc2]
tab wwc_edincome if RDswitch==1 [aw=weight_wwc2]
tab nonRswitch if bush==1 [aw=weight_wwc2]
tab wwc_edincome if nonRswitch==1 [aw=weight_wwc2]
tab nonDswitch if kerry==1 [aw=weight_wwc2]
tab wwc_edincome if nonDswitch==1 [aw=weight_wwc2]


* Estimates for Table A4
gen age = M045193
gen female = (M045192==5)
gen Rswitch = (DRswitch==1)
xi: reg Rswitch wwc_edincome age female [pw=weight_wwc], robust

* Estimates for Table-A5
recode M000523 0/2=1 3=2 4/6=3 7=4, gen(pid3)
tab pid3 if DRswitch==1 [aw=weight_wwc]
tab pid3 if RDswitch==1 [aw=weight_wwc]
tab pid3 if nonRswitch==1 [aw=weight_wwc]
tab pid3 if nonDswitch==1 [aw=weight_wwc]
